package ms.mall.controller;

import ms.common.exception.BizException;
import ms.common.util.string.StringUtil;
import ms.mall.bean.UserParamBean;
import ms.mall.config.ResponseCode;
import ms.mall.service.UserService;
import ms.mall.vo.UserParamVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Project Name: ms
 * File Name: UserController
 * Package Name: ms.shop.controller
 * Date: 2018/6/4  14:20
 * Copyright (c) 2018, tianyul All Rights Reserved.
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 注册/登录
     * @param userParamBean
     * @return
     */
    @PostMapping(value = "/sign")
    public UserParamVo sign(@RequestBody UserParamBean userParamBean) {
        if(StringUtil.isEmpty(userParamBean.getCode())) {
            throw new BizException(ResponseCode.PARAM_ILLEGAL_ERROR, "code不能为空");
        }
        return userService.sign(userParamBean.getCode());
    }

    /**
     * 创建用户信息
     * @param userParamBean
     * @return
     */
    @PostMapping(value = "/create")
    public UserParamVo create(@RequestBody UserParamBean userParamBean) {
        return userService.create(userParamBean);
    }


}
